﻿using System;
using System.Web;
using System.Data;

namespace msBsc.WebUi
{
    public partial class wfLoginIFrame : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        { 
        }
        public override void DoAction()
        {
            if (this.strAction == "doLogin")
            {
                if (this.GetParamHtValue("USER_NME") == string.Empty || this.GetParamHtValue("USER_PASS") == string.Empty || this.GetParamHtValue("VALIDATE_CDE") == string.Empty)
                {
                    Alert("登录不成功：请输入登录名、密码、校验码！");
                    return;
                }
                if (this.GetParamHtValue("VALIDATE_CDE") != (string)GetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, "2"))
                {
                    this.ExecJScript("jQuery.getValidateImg('J_CheckCodeContainer');");
                    this.Alert("验证码错误或已过期，请重新录入！");
                    return;
                }
                //msBsc.AppLogic.Cfg.UserInfo oUserInfo = new AppLogic.Cfg.UserInfo();
                string strRet = msBsc.SvRef.UserInfo.Login(this.GetParamHtValue("USER_NME"), this.GetParamHtValue("USER_PASS"));
                if (strRet != "OK")
                {
                    strRet = msBsc.SvRef.UserInfo.LoginMail(this.GetParamHtValue("USER_NME"), this.GetParamHtValue("USER_PASS"));
                }
                if (strRet != "OK")
                {
                    Alert("输入的登录名或密码错误！");
                    return;
                }

                //暂时的，以后不用
                using (msBsc.AppLogic.DataAlc.CBizSysUser objuser = new AppLogic.DataAlc.CBizSysUser())
                {
                    objuser.AddCustomerInfo(this.GetParamHtValue("USER_NME"));
                }


                this.ExecJScript("LS.set('CURR_LOGIN_USR_NME','" + this.GetParamHtValue("USER_NME") + "');");
                this.ExecJScript("if(parent &&parent.doLoginOk){parent.doLoginOk();} ");
                this.ExecJScript(@"if(parent &&parent.layer){var index = parent.layer.getFrameIndex(window.name);setTimeout(function(){parent.layer.close(index);},200);}");

                SetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, null, "2");
            }
        }

    }
}